<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no" />
	<title>首页</title>

	<style>
		body {
			background-color: #000;

			outline: 0;
		}

	</style>
</head>

<body>

</body>

<script type="text/javascript" src="../j/api.js"></script>
<script type="text/javascript" src="../j/suxiangw.js"></script>
<script type="text/javascript">
	var oxPlayer, di_data, video_index_i, video_index_p, video_index_xh, ad_list_video, _root = 1,
		systemType;
	var list_data = [];
	var video_url_ajax = 'video/lists/limit/200';
	apiready = function() {
		systemType = api.systemType;
		video_index_i = video_index_xh = 0;
		video_index_p = 1;

		oxPlayer = api.require('oxPlayer');
		// console.log(api.winWidth)

		oxPlayer.addEventListener(function(ret, err) {
				 console.log(JSON.stringify(ret));
				switch (ret.code) {
					case 0:
						// 返回
						if (api.winName == 'root') {
							return;
						}
						_close();
						break;
					case 1:
						// 右滑
						break;
					case 2:
						// 单击
						break;
					case 4:
						data_ajax();
						// 滑动到最后一个视频
						break;
					case 5:

						setTimeout(function() {
							 console.log('延迟')
						}, 300)

						break;
					case 6:
						// start开始 pause暂停
						break;
					case 8:
						// 缓冲时返回
						break;
					case 10:
						// alert('放完了')
						// 播放完成
						break;
					case 99990:
						// 会员头像
						_u(ret.userInfo.uid);
						break;
					case 3:
						// 双击
						var userInfo = ret.userInfo;
						userInfo.isLike = true;
						userInfo.likeNum = userInfo.likeNum + 1;
						oxPlayer.updateUserInfo({
							vid: ret.vid,
							userInfo: userInfo
						});
						_zan(ret.vid,'',true);
						_zhen();
						break;
					case 99991:
						// 点赞
						if (!_getPrefs('_user')) {
							return _login();
						}
						console.log(JSON.stringify(ret))
						var userInfo = ret.userInfo;
						if (ret.isLike == 1) {
							_zhen();
							userInfo.isLike = ret.isLike;
							userInfo.likeNum = userInfo.likeNum+1;
						} else {
							userInfo.isLike = ret.isLike;
							userInfo.likeNum = userInfo.likeNum-1;
						}
						oxPlayer.updateUserInfo({
							vid: ret.vid,
							userInfo: userInfo
						});
						_zan(ret.vid);
						break;
					case 99992:
						// 评论
						_ping(ret.vid, ret.userInfo.commentNum, true);
						break;
					case 99993:
						// 分享
						_fenxiang(di_data);
						break;
					case 99994:
						// 关注按钮
						if (!_getPrefs('_user')) {
							return _login();
						}
						setTimeout(function(){
							// var a = {type:'focus',hidden:true,code:99994,scroll:true};
							// var a = {vid:di_data.id,component:a}
							var userInfo = ret.userInfo;
							userInfo.isFocus = true;
							oxPlayer.updateUserInfo({
								vid: di_data.id,
								userInfo: userInfo
							});

							//
							// oxPlayer.updateComponent(a);
						},systemType == 'ios' ? 0 : 250)
						break;
					case 13:
						console.log(JSON.stringify(ret))
						// return;
						// if(ret.state == 2){
						//
						// 	api.setFrameAttr({
						// 		name: 'ab',
						// 		rect:{
						// 			x:api.winWidth + ret.x,
						// 			y:0,
						// 			w:api.winWidth,
						// 			h:'auto'
						// 		}
						// 	});
						//
						// }else if(ret.state == 3){
						//
						// 		api.setFrameAttr({
						// 			name: 'ab',
						// 			rect:{
						// 				x:api.winWidth,
						// 				y:0,
						// 				w:api.winWidth,
						// 				h:'auto'
						// 			}
						// 		});
						// 	if(ret.x <= -80){
						// 			_u(di_data.uid)
						// 	}
						//
						//
						// }
						break;
					default:
				}
			});
		data_ajax();
		// 回到屏幕
		api.addEventListener({
			name: 'viewappear'
		}, function(ret, err) {
			isPlaying(true);
		});
		// 离开屏幕
		api.addEventListener({
			name: 'viewdisappear'
		}, function(ret, err) {
			isPlaying();
		});
		//应用进入后台事件
		api.addEventListener({
			name: 'pause'
		}, function(ret, err) {
			isPlaying();
		});
		// 应用从后台回到前台事件
		api.addEventListener({
			name: 'resume'
		}, function(ret, err) {
			// isPlaying(true);
		});
	};

	function data_ajax() {
		alert("刷新了")

		_ajax(video_url_ajax, function(ret, err) {

			if (ret) {
				var data = [];


					ret = ret.data;
					if (ret) {
						for (var i = 0; i < ret.length; i++) {
							data.push(find(ret[i]));
							list_data.push(ret[i]);
						}
					}

					var marginBottom = api.safeArea.bottom + 50;

					var dbPlay = {
						fixedOn: api.frameName,
						rect: {
							x: 0,
							y: 0,
							w: 'auto',
							h: 'auto'
						},
						fixed: true,
						index: 0,
						event: 'MyClickEvent', //点击事件
						openCache: true,
						rightSlide: false,
						leftSlide:false,
						showBack: api.winName == 'root' ? false : true, //返回按钮是否显示事件返回code:0滑动返回code:1android有效
						showDoubleClick: true, //双击红心点赞事件返回code:3
						// playBtn: _i + 'pause_start.png', //中间播放按钮图片(自定义) 可选 没有则用系统自带
						marginBottom: marginBottom, //进度条距离底部距离
						backgroundColor: '#000000',
						// backgroundHolder: _i + 'loading_720.png',
						// avatarHolder:_i + 'touxiang.png',
						downFresh:false,//下拉刷新开关事件返回code:12
	        	upFresh:false,//上拉拉刷新开关事件返回code:13
						styles: find_style(),
						data: data
					};
					oxPlayer.dbPlay(dbPlay);


			}
		})
	}

	function find(ret) {
		var a = {};
		if(ret.ad){
			a.vid = ret.ad.id;
		}else{
			a.vid = ret.id;
		}

		if(ret.ad){
			 a.title = "";
		}else{
			a.title = "@" + ret.user.username + "\r\n\r\n" + ret.content;
		}
		var thumb = ret.img;
		if(ret.ad){
			thumb = ret.ad.img;
		}
		a.thumb = _img(thumb, api.winWidth, api.winHeight);
		a.url = _sx_qiniu + (ret.ad ? ret.ad.video : ret.url);

		var b = {};
		b.uid = ret.uid;
		b.userName = ret.user.username;
		b.avatar = _img(ret.user.img, 100, 100);
		b.isFocus = false;
		b.likeNum = ret.zan_num;
		b.isLike = ret.user_zan ? true : false;
		b.commentNum = ret.ping_num;
		b.shareNum = 0;
		a.userInfo = b;

		var b = {};
		b.musicId = ret.uid;
		b.musicName = ret.user.username;
		b.musicIcon =  _img(ret.user.img, 100, 100) ;
		a.music = b;
		return a;
	}


	function find_style() {
		//code  0 返回  1 右滑 2 单击  3 双击  4滑到最后一个视频返回5 播放记录放回index滚动到播放记录索引 //按钮类型:music(带动画的音乐按钮),comment(评论),share(分享),like(红心点赞),avatar(头像),focus(关注),title(标题),desc(简介),musicName(音乐滚动字幕),hoverText(评论输入框),component自定义组件,
		//xywh 控件 位置 大小
		//pic 图片 音乐封面 图标图片 按钮背景图片等
		//pic1 评论输入框 pic1 图标 pic2 发送图标
		//component 自定义控件  radius 圆角值 backgroundColor 背景色 border 边框 borderColor边框颜色 scroll 是否随视频滚动
		//alignment 文字对齐0:居中 1上左对齐 2上中对齐 3上右对齐 4上两端对齐 5下左对齐 6下中对齐 7下右对齐 8下两端对齐 9居中两端对齐
		//textSize:14  文字大小 textColor:'#C0FF3E' 文字颜色 alpha 背景透明度
		//hidden 是否隐藏  processColor 进度条颜色(需要进度条添加)
		//code:16//控件标识  同时作为点击事件返回码 0，1,2,3,4,5占用 不能使用 组件 code值不能重复 rect 图片位置(相对父组件component位置)
		var h = api.winHeight;
		var w = api.winWidth;
		var music, share, comment, like, avatar, focus, title, userName, musicName, hoverText, component = {};

		var x = w - (systemType == 'ios' ? 50 : 50);
		var y = h - 375 - api.safeArea.bottom;

		if(api.winName != 'root'){
			y = y + 60
		}

		var y_r = 85;
		var w_s = 40;
		var h_s = 40;
		var zan_r = 12;
		var num_ico = systemType == 'ios' ? 35 : 40;
		avatar = {
			type: 'avatar',
			x: x - (zan_r / 2),
			y: y,
			w: w_s + zan_r,
			h: h_s + zan_r,
			pic: '',
			radius: 25,
			border:1,
			borderColor: '#FFFFFF',
			hidden: false,
			code: 99990,
		}; //头像
		var focus_w = systemType == 'ios' ? 33 : 30;
		focus = {
			type: 'focus',
			x: x + (systemType == 'ios' ? 4 : 5),
			y: y + (systemType == 'ios' ? 35 : 35),
			w: focus_w,
			h: focus_w,
			pic: '',
			hidden: false,
			code: 99994,
		}; //关注
		y = y + y_r;
		like = {
			type: 'like',
			x: x - (systemType == 'ios' ? 0 : 5),
			y: y,
			w: w_s + (systemType == 'ios' ? 0 : 10),
			h: h_s + (systemType == 'ios' ? 0 : 10),
			// pic:_i+'zan.png',
			// pic1:_i+'zan-s.png',
			hidden: false,
			code: 99991,
			num: {
				hidden: false,
				textColor: '#FFFFFF',
				textSize: 14,
				// marginTop: systemType == 'ios' ? 10 : 20,
				// marginRight:systemType == 'ios' ? 50 : 16,
				x: x - (systemType == 'ios' ? 0 : 5),
				y: y + num_ico + (systemType == 'ios' ? -5 : +5),
				w: w_s + (systemType == 'ios' ? 0 : 10),
				h: h_s + (systemType == 'ios' ? 0 : 10),
			}
		}; //红心点赞
		y = y + y_r;
		comment = {
			type: 'comment',
			x: x,
			y: y,
			w: w_s,
			h: h_s,
			hidden: false,
			code: 99992,

			num: {
				hidden: false,
				textColor: '#FFFFFF',
				textSize: 14,
				// marginTop: systemType == 'ios' ? 10 : 20,
				// marginRight:systemType == 'ios' ? 50 : 16,
				x: x,
				y: y + num_ico,
				w: w_s,
				h: h_s - (systemType == 'ios' ? 10 : 0),
			}

		}; //评论
		y = y + y_r;
		share = {
			type: 'share',
			x: x,
			y: y,
			w: w_s,
			h: h_s,
			hidden: false,
			code: 99993,
		}; //分享
		if (time_jinbi) {
			_right_h = y;
		}

		userName = {};

		//	用户昵称

		// component = {
		// 	type: 'component',
		// 	x: x,
		// 	y: y,
		// 	w: w - x - y_r,
		// 	h: 30,
		// 	text: '@速翔网络',
		// 	textSize: 16,
		// 	textColor: '#FFFFFF',
		// 	alignment: 1,
		// 	hidden: false,
		// 	code: 99990,
		// }; //自定义组件
		y = h - 200 - api.safeArea.bottom;
		if(api.winName == 'root'){

		}else{
			y = y + 60;
		}
		x = 0;
		w = w - 50
		if (systemType == 'ios') {
			y = y + 20;
			x = x + 15;
			w = w - 30;
		}
		//视频简介
		title = {
			type: 'title',
			x: x,
			y: y,
			w: w,
			h: systemType == 'ios' ? 120 : 150,
			textSize: 16,
			textColor: '#FFFFFF',
			hidden: false,
			code:99995
		}; //用户名
		music = {}; //旋转音乐
		musicName = {}; //音乐滚动字幕
		hoverText = {}; //评论输入框 pic1 @图标 pic2 发送图标 text 输入框placeholder文字


		var styles = [music, share, comment, like, avatar, focus, title, userName, musicName, hoverText, component];
		return styles;
	}
	// 开始播放
	function isPlaying(a) {

	}
	var time_jinbi = true;
	// 打开奖励圆度倒计时
	function yuandu() {


	}
	// 付费视频观看
	function fufei() {

	}
	function goumai(){

	}
</script>

</html>
